--
-- Author: shunguo.chen
-- Date: 2019-05-17 16:52:51
--
-- LegendStar   传奇星魂
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
    self.id = 0
    self.lv = 0

    if data then
        self:init(data)
    end
end

-- message StarMapSkill {
--     int32 ID        = 1;
--     int32 Level = 2;
-- }
function ClassRef:init(data)
    local preId = self.id
    self.id = data.ID
    self.lv = data.Level

    if self.id ~= preId then
        -- conf
        local conf = GD:getLegendStarConf(self.id)
        self._conf = conf
        self.seat = tonumber(conf.seat or 0)

        -- 开启条件
        local preSeatStr = conf.proSeat
        local conditionStr = conf.require
        local conditions = {}
        if preSeatStr and conditionStr then
            local posAry = table.tonumber(string.split(preSeatStr, ";"))
            local conditionAry = string.splitTwice(conditionStr, nil, true)
            if #posAry == #conditionAry then
                local condition
                for i,v in ipairs(posAry) do
                    condition = {}
                    condition.seat = v
                    condition.starId = conditionAry[i][1]
                    condition.starLv = conditionAry[i][2]
                    conditions[#conditions + 1] = condition
                end
            end
        end
        self.conditions = conditions

        -- lvParams
        local lvParams = {}
        local propAry = string.splitTwice(conf.prop, nil, true)
        local costAry = string.split(conf.cost, "#")
        local weightAry = table.tonumber(string.split(conf.weight, ";"))
        local lvParam
        for i,v in ipairs(propAry) do
            lvParam = {}
            lvParam.propId = v[1]
            lvParam.propVal = v[2]
            lvParam.costItems = UD:parseItemsFromString(costAry[i])
            lvParam.weight = weightAry[i]
            lvParams[#lvParams + 1] = lvParam
        end

        -- dump(lvParams, "lvParams", 5)

        self._lvParams = lvParams
        self.maxLv = #lvParams
    end
end

function ClassRef:getId()
    return self.id
end

function ClassRef:isActive()
    return self.lv > 0
end

function ClassRef:isFull()
    return self.lv == self.maxLv
end

-- 获取当前等级升级所需道具
-- lv 当前等级
function ClassRef:getLvUpCostItems(lv)
    local lvParam = self._lvParams[lv+1]
    return lvParam.costItems
end

-- 获取星魂属性
function ClassRef:getStarProp(lv)
    lv = lv or 1
    lv = math.min(lv, self.maxLv)
    local lvParam = self._lvParams[lv]
    return lvParam.propId, lvParam.propVal
end

-- 获取星魂当前属性
function ClassRef:getCurStarProp()
    if self.lv > 0 then
        local lvParam = self._lvParams[self.lv]
        return lvParam.propId, lvParam.propVal
    end
end

function ClassRef:getName()
    return L(self._conf.name or "--")
end

function ClassRef:getShowStr()
    local propId = self._lvParams[1].propId
    local conf = GD:getLegendPropShowConf(propId)
    if conf then
        return L(conf.showStringNoLV), L(conf.showStringLV)
    end
    return "", ""
end

function ClassRef:getIcon()
    if not self._icon then
        self._icon = table.concat({"art/legend/", self._conf.icon, ".png"})
    end
    return self._icon
end

return ClassRef